<?php
use think\Db;
/** 模块中的公用函数 **/
//创建TOKEN
function create_token() {
    $code = chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE)) . chr(mt_rand(0xB0, 0xF7)) . chr(mt_rand(0xA1, 0xFE));
    // 加密
    $token = md5("ADMIN" . substr(md5($code), 8, 10));

    session('TOKEN', $token);
}

//判断TOKEN
function check_token($token) {
    if ($token == session('TOKEN')) {
        session('TOKEN', NULL);
        return TRUE;
    } else {
        return FALSE;
    }
}